/**
* CORBA SERVER PROVIDING ONE REMOTE SERVICE TO THE RMI SERVER
* USE THE COMMAND INTERFACE TO PRINT THE TRACE OF ACTIVITIES OF THIS SERVER
*/
package corbaServer;

import org.omg.CORBA.ORB;
import org.omg.CORBA.ORBPackage.InvalidName;
import org.omg.CosNaming.NameComponent;
import org.omg.CosNaming.NamingContextExt;
import org.omg.CosNaming.NamingContextExtHelper;
import org.omg.CosNaming.NamingContextPackage.CannotProceed;
import org.omg.CosNaming.NamingContextPackage.NotFound;
import org.omg.PortableServer.POA;
import org.omg.PortableServer.POAHelper;
import org.omg.PortableServer.POAManagerPackage.AdapterInactive;
import org.omg.PortableServer.POAPackage.ServantNotActive;
import org.omg.PortableServer.POAPackage.WrongPolicy;

import corbaServer.corba.ICorbaServer;
import corbaServer.corba.ICorbaServerHelper;

public class CorbaRaceServer 
{

public static void main(String[] args) throws InvalidName, AdapterInactive, ServantNotActive, WrongPolicy, org.omg.CosNaming.NamingContextPackage.InvalidName, NotFound, CannotProceed
{
	String orbProperties[] = {"-ORBInitialHost", args[0], "-ORBInitialPort", args[1]};
	ORB orb = ORB.init(orbProperties, null);

	CorbaServer servidor = new CorbaServer(args[2]);

	POA rootPOA = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
	rootPOA.the_POAManager().activate();

	
	org.omg.CORBA.Object servantRef = rootPOA.servant_to_reference(servidor);
	ICorbaServer iCorbaServerRef = ICorbaServerHelper.narrow(servantRef);

	org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");
	NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);

	String name = args[2];
	NameComponent path[] = ncRef.to_name(name);
	ncRef.rebind(path, iCorbaServerRef);
	System.out.println("Server running and waiting...");
	orb.run();

}

}